local Lua__Blast = fk.CreateSkill {
    name = "Lua__Blast",
    tags = {Skill.Permanent}
}


Fk:loadTranslationTable{
  ["Lua__Blast"] = "Blast",
  [":Lua__Blast"] = "持恒技，共鸣技，一名角色判定阶段开始时，你可以对其使用你手中可使用的所有基本牌/锦囊牌/装备牌。",
  ["#Lua__Blast-prompt"] = "Blast：你可对 %src 使用你手中的所有基本牌/锦囊牌/装备牌中的一种。",
  ["#Lua__Blast-basic"] = "基本牌",
  ["#Lua__Blast-trick"] = "锦囊牌",
  ["#Lua__Blast-equip"] = "装备牌",
}




Lua__Blast:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(Lua__Blast.name) and target.phase == Player.Judge and not player:isKongcheng() and
        (player.general == "DIEND" or player.deputyGeneral == "DIEND") then
            local hasBasic = false
            local hasTrick = false
            local hasEquip = false
            local room = player.room
            
            for _, id in ipairs(player:getCardIds("h")) do
                if not player:isProhibited(target, Fk:getCardById(id)) then
                    local card = Fk:getCardById(id)
                    if card.type == Card.TypeBasic then hasBasic = true end
                    if card.type == Card.TypeTrick then hasTrick = true end
                    if card.type == Card.TypeEquip then hasEquip = true end
                end
            end
            
            return (hasBasic or hasTrick or hasEquip)
        end
    end,
    
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if room:askToSkillInvoke(player, {skill_name = Lua__Blast.name, prompt = "#Lua__Blast-prompt:" .. target.id}) then
            local choices = {}

            local hasBasic = false
            local hasTrick = false
            local hasEquip = false
            
            for _, id in ipairs(player:getCardIds("h")) do
                if not player:isProhibited(target, Fk:getCardById(id)) then
                    local card = Fk:getCardById(id)
                    if card.type == Card.TypeBasic then hasBasic = true end
                    if card.type == Card.TypeTrick then hasTrick = true end
                    if card.type == Card.TypeEquip then hasEquip = true end
                end
            end
            
            if hasBasic then table.insert(choices, "#Lua__Blast-basic") end
            if hasTrick then table.insert(choices, "#Lua__Blast-trick") end
            if hasEquip then table.insert(choices, "#Lua__Blast-equip") end
            
            if #choices > 0 then
                local choice = room:askToChoice(player, {
                    choices = choices,
                    skill_name = Lua__Blast.name
                })
                room:setTag("Lua__Blast_cardType_" .. player.id, choice)
                return true
            end
        end
        return false
    end,
    
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cardType = room:getTag("Lua__Blast_cardType_" .. player.id)
        local cardTypeMap = {
            ["#Lua__Blast-basic"] = Card.TypeBasic,
            ["#Lua__Blast-trick"] = Card.TypeTrick,
            ["#Lua__Blast-equip"] = Card.TypeEquip
        }
        
        local selectedType = cardTypeMap[cardType]
        local ids = table.filter(player:getCardIds("h"), function(id)
            local card = Fk:getCardById(id)
            return card.type == selectedType and not player:isProhibited(target, card)
        end)
        
        if #ids == 0 then 
            return 
        end
        
        for _, id in ipairs(ids) do
            if player.dead or target.dead then return end
            if table.contains(player:getCardIds("h"), id) then
                local card = Fk:getCardById(id)
                if player:canUseTo(card, target, { bypass_times = true, bypass_distances = true }) then
                    local use = {
                        from = player,
                        tos = {target},
                        card = card,
                        extraUse = true,
                    }
                    use.extra_data = use.extra_data or {}
                    use.extra_data.mouni_use = player.id
                    room:useCard(use)
                end
            end
        end
    end,
})




return Lua__Blast 